home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 6
/
FM Towns Free Software Collection 6.iso
/
t_os
/
qa
/
src
/
aoi_lib1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-08
|
12KB
|
479 lines
// 葵ライブラリ ///// Tab Size : 4 /////
// ///// Margin : 120 /////
// aoi_lib1.c v1.0 L11
//
// (C)K.Konishi 07-Nov-92
//
#define LIB
#include <EGB.h>
#include <MOS.h>
#include "aoi_lib1.h"
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <msdos.cf>
// #define TEST
// 上の行の // を取るとサンプルプログラムが出来上がります。
#define MDCL1 1 // 色の名前
#define MDCL2 2
#define MDCL3 3
#define MDCL4 4
#define MDCL5 5
#define MDCL6 9 // 6から9に変えています
#define MDCL7 7
#define BLACK 8
#define BLUE 9
#define RED 10
#define PURPLE 11
#define GREEN 12
#define SKYBLUE 13
#define YELLOW 14
#define WHITE 15
int AOIstring(short x, short y, AOIstringData *Data, char *tx)
{
AOIstringData Dt = *Data;
EGB_color(work, 0, Dt.sc);
EGB_fontStyle(work, Dt.ss);
EGB_textZoom(work, 1, Dt.sx, Dt.sy);
EGB_textZoom(work, 0, Dt.ax, Dt.ay);
WORD(para + 0) = x;
WORD(para + 2) = y;
WORD(para + 4) = strlen(tx);
strcpy((para + 6), tx);
return EGB_sjisString(work, para);
}
int AOIline(short x0, short y0, short x1, short y1, short c)
{
EGB_color(work, 0, c);
WORD(para + 0) = 2;
WORD(para + 2) = x0;
WORD(para + 4) = y0;
WORD(para + 6) = x1;
WORD(para + 8) = y1;
return EGB_connect(work, para);
}
int AOIconnectLeft(short x0, short y0, short x1, short y1, short c)
{
EGB_color(work, 0, c);
WORD(para + 0) = 3;
WORD(para + 2) = x0;
WORD(para + 4) = y1;
WORD(para + 6) = x0;
WORD(para + 8) = y0;
WORD(para + 10) = x1;
WORD(para + 12) = y0;
return EGB_connect(work, para);
}
int AOIconnectRight(short x0, short y0, short x1, short y1, short c)
{
EGB_color(work, 0, c);
WORD(para + 0) = 3;
WORD(para + 2) = x0;
WORD(para + 4) = y1;
WORD(para + 6) = x1;
WORD(para + 8) = y1;
WORD(para + 10) = x1;
WORD(para + 12) = y0;
return EGB_connect(work, para);
}
int AOIbox(short x0, short y0, short x1, short y1, short c)
{
EGB_color(work, 0, c);
WORD(para + 0) = x0;
WORD(para + 2) = y0;
WORD(para + 4) = x1;
WORD(para + 6) = y1;
return EGB_rectangle(work, para);
}
int AOIboxFull(short x0, short y0, short x1, short y1, short c)
{
int ret = 0;
ret = EGB_color(work, 0, c);
for (; y0 <= y1; y0++) {
WORD(para + 0) = 2;
WORD(para + 2) = x0;
WORD(para + 4) = y0;
WORD(para + 6) = x1;
WORD(para + 8) = y0;
ret += EGB_connect(work, para);
}
return ret;
}
int AOIwinBase(short x, short y, short lx, short ly, short sd)
{
int i;
if (sd == 1) {
EGB_pastel(work, 128);
i = AOIboxFull(x + lx + 1, y + 6, x + lx + 6, y + ly + 7, MDCL1)
| AOIboxFull(x + 6, y + ly + 1, x + lx + 6, y + ly + 7, MDCL1);
}
return i
| AOIboxFull(x, y, x + lx, y + ly, MDCL6)
| AOIconnectLeft (x , y , x + lx - 1, y + ly - 1, WHITE)
| AOIconnectRight(x , y , x + lx , y + ly , MDCL1)
| AOIconnectLeft (x + 4, y + 4, x + lx - 5, y + ly - 5, MDCL1)
| AOIconnectRight(x + 4, y + 4, x + lx - 4, y + ly - 4, WHITE);
}
int AOIbuttonBase(short x, short y, short lx, short ly)
{
return AOIboxFull(x + 1, y + 1, x + lx - 1, y + ly - 1, MDCL6)
| AOIconnectLeft (x, y, x + lx - 1, y + ly - 1, WHITE)
| AOIconnectRight(x, y, x + lx , y + ly , MDCL1);
}
int AOIsetPalette(int cn, int cg, int cr, int cb)
{
DWORD(para + 0) = 1;
DWORD(para + 4) = cn; /* cn 色識別番号 */
BYTE(para + 8) = cb * 17; /* cb 青 */
BYTE(para + 9) = cr * 17; /* cr 赤 */
BYTE(para + 10) = cg * 17; /* cg 緑 */
BYTE(para + 11) = 0;
return EGB_palette(work, 1, para); /* display レイヤ表示 */
}
int AOIsetPalette256(int cn, int cg, int cr, int cb)
{
DWORD(para + 0) = 1;
DWORD(para + 4) = cn; /* cn 色識別番号 */
BYTE(para + 8) = cb * 257; /* cb 青 */
BYTE(para + 9) = cr * 257; /* cr 赤 */
BYTE(para + 10) = cg * 257; /* cg 緑 */
BYTE(para + 11) = 0;
return EGB_palette(work, 1, para); /* display レイヤ表示 */
}
int AOIcolorIGRB(int g, int r, int b)
{
return EGB_colorIGRB(work, 0, g * 0x10000 + r * 0x100 + b);
}
int AOIsetStandardPalette(void)
{
return AOIsetPalette( 8, 0, 0, 0)
| AOIsetPalette( 9, 0, 0, 15)
| AOIsetPalette(10, 0, 15, 0)
| AOIsetPalette(11, 0, 15, 15)
| AOIsetPalette(12, 15, 0, 0)
| AOIsetPalette(13, 15, 0, 15)
| AOIsetPalette(14, 15, 15, 0)
| AOIsetPalette(15, 15, 15, 15);
}
void AOIsetButton(AOIbuttonData *Data, short x, short y, short lx, short ly)
{
AOIbuttonData bData;
bData.x = x;
bData.y = y;
bData.lx = lx;
bData.ly = ly;
*Data = bData;
}
int AOIbutton(short sx, short sy, int mx, int my, AOIbuttonData *Data)
{
AOIbuttonData *Dt = Data;
int i;
for (i = 0; i <= BUTTON; i++) {
if (sx + Dt[i].x < mx && mx < sx + Dt[i].x + Dt[i].lx && sy + Dt[i].y < my && my < sy + Dt[i].y + Dt[i].ly) {
return i;
}
}
return -1;
}
void _AOIfigureDrawSet(short *fig, short *a)
{
short *da = a;
switch (*fig) {
case 0 :
da[1] = da[2] = da[3] = da[4] = da[5] = da[7] = 1;
break;
case 1 :
da[4] = da[5] = 1;
break;
case 2 :
da[1] = da[4] = da[6] = da[3] = da[7] = 1;
break;
case 3 :
da[1] = da[4] = da[6] = da[5] = da[7] = 1;
break;
case 4 :
da[2] = da[6] = da[4] = da[5] = 1;
break;
case 5 :
da[1] = da[2] = da[6] = da[5] = da[7] = 1;
break;
case 6 :
da[1] = da[2] = da[3] = da[6] = da[5] = da[7] = 1;
break;
case 7 :
da[1] = da[2] = da[4] = da[5] = 1;
break;
case 8 :
da[1] = da[2] = da[3] = da[4] = da[5] = da[6] = da[7] = 1;
break;
case 9 :
da[1] = da[2] = da[4] = da[5] = da[6] = da[7] = 1;
break;
}
}
void AOIfigureDraw(short sx, short sy, short figure)
{ // 2桁の数字を12ドットで表示します
short a[8];
short fig[3]; // fig[1] : 10の位 fig[2] : 1の位
short i, j;
for (i = 0; i <= 7; i++) a[i] = 0;
for (i = 0; i <= 2; i++) fig[i] = 0;
if (figure < 0) figure = 0; // 負の数は0にする
fig[1] = figure / 10;
fig[2] = figure - fig[1] * 10;
for (i = 1; i != 3; i++) {
_AOIfigureDrawSet(&fig[i], a);
if (i == 2) sx += 10;
AOIline(sx + 1, sy , sx + 5, sy , a[1] == 1 ? 15 : 8);
AOIline(sx , sy , sx , sy + 5, a[2] == 1 ? 15 : 8);
AOIline(sx , sy + 7, sx , sy + 12, a[3] == 1 ? 15 : 8);
AOIline(sx + 6, sy , sx + 6, sy + 5, a[4] == 1 ? 15 : 8);
AOIline(sx + 6, sy + 7, sx + 6, sy + 12, a[5] == 1 ? 15 : 8);
AOIline(sx + 1, sy + 6, sx + 5, sy + 6, a[6] == 1 ? 15 : 8);
AOIline(sx + 1, sy + 12, sx + 5, sy + 12, a[7] == 1 ? 15 : 8);
for (j = 0; j <= 7; j++) a[j] = 0;
}
}
void AOIfigureDraw2(short sx, short sy, int figure) // 2桁の数字を25ドットで表示します
{
short a[8];
short fig[3]; // fig[1] : 10の位 fig[2] : 1の位
short i, j, k;
short m = 0, n;
for (i = 0; i <= 7; i++) a[i] = 0;
for (i = 0; i <= 2; i++) fig[i] = 0;
if (figure < 0) figure = 0; // 負の数は0にする
fig[1] = figure / 10;
fig[2] = figure - fig[1] * 10;
for (i = 1; i != 3; i++) {
_AOIfigureDrawSet(&fig[i], a);
if (i == 2) sx += 20;
for (k = 0; k < 4; k++) {
sx += k;
if (k == 0 || k == 3) m = 1;
else m = 0;
for (n = 0; n < 2; n++) {
AOIline(sx + n * 11, sy + 3 + m, sx + n * 11, sy + 11 - m, a[2 + n * 2] == 1 ? 14 : 8);
AOIline(sx + n * 11, sy + 14 + m, sx + n * 11, sy + 22 - m, a[3 + n * 2] == 1 ? 14 : 8);
}
sx -= k;
}
for (k = 0; k < 4; k++) {
sy += k;
if (k == 0 || k == 3) m = 1;
else m = 0;
AOIline(sx + 3 + m, sy , sx + 11 - m, sy , a[1] == 1 ? 14 : 8);
AOIline(sx + 3 + m, sy + 11, sx + 11 - m, sy + 11, a[6] == 1 ? 14 : 8);
AOIline(sx + 3 + m, sy + 22, sx + 11 - m, sy + 22, a[7] == 1 ? 14 : 8);
sy -= k;
}
for (j = 0; j <= 7; j++) a[j] = 0;
}
}
short _AOIrandom(short max) // 0~99までの特殊用途乱数発生
{
short i10, max10, ret;
max10 = max / 10;
while((i10 = rand() % 10) >= max10);
ret = i10 * 10 + (rand() % 10);
if (ret >= max) return _AOIrandom(max);
return ret;
}
long AOIrandom(long max) // 0~999999までの乱数発生
{
time_t *t = 0;
srand((unsigned int)time(t));
if (max > 9999) {
return _AOIrandom(max / 10000) * 10000
+ _AOIrandom(99) * 100
+ _AOIrandom(99);
}
if (max > 99) {
return _AOIrandom(max / 100) * 100
+ _AOIrandom(99);
}
return _AOIrandom(99);
}
int AOIbuttonLamp(short sx, short sy, AOIbuttonData *Data) // ボタン部分を反転
{
AOIbuttonData Dt = *Data;
return EGB_writeMode(work, 4)
| MOS_disp(0)
| AOIboxFull(sx + Dt.x, sy + Dt.y, sx + Dt.x + Dt.lx, sy + Dt.y + Dt.ly, 15)
| MOS_disp(1)
| EGB_writeMode(work, 0);
}
int AOIgetGraph(char *buf, short x0, short y0, short x1, short y1) // 画像データ画面の読み込み
{
DWORD(para + 0) = (unsigned int)buf;
WORD (para + 4) = getds();
WORD (para + 6) = x0;
WORD (para + 8) = y0;
WORD (para + 10) = x1;
WORD (para + 12) = y1;
return EGB_getBlock(work, para); // ドットデータの読み込み1
}
int AOIputGraph(char *buf, short x0, short y0, short x1, short y1) // 画像データ画面の書き込み
{
DWORD(para + 0) = (unsigned int)buf;
WORD (para + 4) = getds();
WORD (para + 6) = x0;
WORD (para + 8) = y0;
WORD (para + 10) = x1;
WORD (para + 12) = y1;
return EGB_putBlock(work, 0, para); // ドットデータの書き込み1
}
void AOIwindowMove(char *dispTmp, short *sx, short *sy, short lx, short ly) // ウインドゥ移動
{
int ch, mx, my;
int dx, dy;
char dispTmp2[(640/8)*480]; // ドットデータの読み書き作業領域
MOS_disp(0);
AOIgetGraph(dispTmp2, *sx, *sy, *sx + lx + 7, *sy + ly + 7);
AOIputGraph(dispTmp, *sx, *sy, *sx + lx + 7, *sy + ly + 7);
MOS_typeRom(83 + 1, 8, 8, pat_work); // マウスを手の平に
MOS_disp(1);
EGB_writeMode(work, 4);
EGB_linePattern(work, 1, 0x55555555);
MOS_rdpos(&ch, &mx, &my);
dx = mx - *sx;
dy = my - *sy;
do {
MOS_rdpos(&ch, &mx, &my);
*sx = mx - dx;
*sy = my - dy;
MOS_disp(0);
AOIbox(*sx, *sy, *sx + lx, *sy + ly, WHITE);
AOIbox(*sx, *sy, *sx + lx, *sy + ly, WHITE);
MOS_disp(1);
} while (ch == 1);
EGB_linePattern(work, 1, 0xffffffff);
EGB_writeMode(work, 0);
MOS_disp(0);
MOS_typeRom(80 + 1, 0, 0, pat_work); // マウスを元通り
AOIgetGraph(dispTmp, *sx, *sy, *sx + lx + 7, *sy + ly + 7);
AOIputGraph(dispTmp2, *sx, *sy, *sx + lx + 7, *sy + ly + 7);
MOS_disp(1);
}
short AOItownsName(void) // TOWNSの機種判別
{
short m;
switch (m = _inp(0x31)) {
case 1..5 :
break;
default :
m = 0; break;
}
return m; // 1 : 初代 2 : 2代目 3 : 3代目 4 : IIUX 5 : IICX
}
// サンプルプログラムは 13行目の // を取ってください
#ifdef TEST
void main(void)
{
AOIstringData AstringD; // AOIstringData型の変数宣言
int i;
EGB_init(work, EgbWorkSize);
EGB_resolution(work, 0, 3);
EGB_resolution(work, 1, 3);
EGB_writePage(work, 0);
AOIsetPalette( 1, 1, 1, 15);
AOIsetPalette( 2, 3, 3, 15);
AOIsetPalette( 3, 5, 5, 15);
AOIsetPalette( 4, 7, 7, 15);
AOIsetPalette( 5, 9, 9, 15);
AOIsetPalette( 6, 11, 11, 15);
AOIsetPalette( 7, 13, 13, 15);
AOIsetStandardPalette();
for (i = 0; i <= 450; i+= 30) AOIboxFull(0, i, 639, i + 30, i / 30);
AstringD.sx = 16; // AOIstring使用例
AstringD.sy = 16;
AstringD.ax = 8;
AstringD.ay = 16;
AstringD.sc = 15;
AstringD.ss = 0x02;
AOIstring(100, 100, &AstringD, "あいうえおjkjkjk");
AOIline(0, 0, 639, 399, 6); // AOIline使用例
AOIbox(100, 100, 200, 399, 7); // AOIbox使用例
AOIboxFull(201, 100, 599, 200, 1); // AOIboxFull使用例
AOIwinBase(250, 150, 350, 200, 1); // AOIwinBase使用例
AOIbuttonBase(255, 155, 340, 16); // AOIbuttonBase使用例
AstringD.sx = 12; // AOIstring使用例
AstringD.sy = 12;
AstringD.ax = 6;
AstringD.ay = 12;
AstringD.sc = BLACK;
AstringD.ss = 0x01;
AOIstring(300, 168, &AstringD, "ウインドゥの試作版です");
}
#endif